<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>    
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximumscale=1">
       <title>Title</title>    
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all"/>
</head>
<body>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/js/jquery-1.12.3.min.js"></script>
<script th:inline="none">
    //Demo
    layui.use(['layer', 'form', 'table'], function () {
        var layer = layui.layer
            , form = layui.form
            , table = layui.table
            , $ = layui.jquery;//引入jquery
        var id=$("#troubleId").val();
        //根据父页面传来的id获取车辆信息并回填
        $.ajax({
            type:"get",
            url:"/troublerecord/troublerecordById",
            data:{id:id},
            success:function(resp){
                console.log(resp.data.troublerecord);
                var troublerecord=resp.data.troublerecord;
                $("#vid").val(troublerecord.vid);
                $("#driverid").val(troublerecord.driverid);
                $("#time").val(troublerecord.time);
                $(":text[name=address]").val(troublerecord.address);
                $(":text[name=reason]").val(troublerecord.reason);
                $(":text[name=oursitu]").val(troublerecord.oursitu);
                $(":text[name=othersitu]").val(troublerecord.othersitu);
                $(":text[name=result]").val(troublerecord.result);
                $(":text[name=ourmoney]").val(troublerecord.ourmoney);
                 $(":text[name=othermoney]").val(troublerecord.othermoney);
                $(":text[name=insuremoney]").val(troublerecord.insuremoney);
                $(":text[name=information]").val(troublerecord.information);
            }
        });

        $.ajax({
            type: "GET",
            url: "/vehiclefiles/selectVehicleAll",
            success: function (res) {
                var vehiclefiles = res.data.vehiclefilesList;
                if (vehiclefiles.length > 0) {
                    for (var i = 0; i < vehiclefiles.length; i++) {
                        var vehiclefile = vehiclefiles[i];
                        var sele='';
                        if(vehiclefile.id==$("#vid").val()){
                            sele='selected';
                        }
                        //追加，注意有坑，需要渲染下拉菜单
                        $("#vehiclenum").append("<option value='" + vehiclefile.id + "' selected='"+sele+"'>" + vehiclefile.vehiclenum + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        })
        $.ajax({
            type: "GET",
            url: "/dictionary/dictionaryType14",
            success: function (res) {
                var dictionarys = res.data.dictionaryList;
                if (dictionarys.length > 0) {
                    for (var i = 0; i < dictionarys.length; i++) {
                        var dictionary = dictionarys[i];
                        var sele='';
                        if(dictionary.id==$("#typeid").val()){
                            sele='selected';
                        }
                        $("#typeid").append("<option value='" + dictionary.id + "' selected='"+sele+"'>" + dictionary.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        });
        $.ajax({
            type: "GET",
            url: "/driver/selectAllDriver",
            success: function (res) {
                var drivers = res.data.drivers;
                if (drivers.length > 0) {
                    for (var i = 0; i < drivers.length; i++) {
                        var driver = drivers[i];
                        var sele='';
                        if(driver.id==$("#driverid").val()){
                            sele='selected';
                        }
                        $("#driverid").append("<option value='" + driver.id + "' selected='"+sele+"'>" + driver.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        });


    });
    var callbackdata=function(){
        var forms = $("#from2").serialize();
        return forms;
    }
</script>

<form class="layui-form" action="" method="" id="from2">

<input type="hidden" id="troubleId" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">车牌号码</label>
        <div class="layui-input-block">
            <select lay-verify="required"  name="vid" id="vehiclenum">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">驾驶员</label>
        <div class="layui-input-block">
            <select lay-verify="required" id="driverid" name="driverid">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">事故时间</label>
        <div class="layui-input-block">
            <input type="date" name="time" required  lay-verify="required" placeholder="请输入违章时间"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">事故地点</label>
        <div class="layui-input-block">
            <input type="text" name="address" required  lay-verify="required" placeholder="填写地点"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">事故原因</label>
        <div class="layui-input-block">
            <input type="text" name="reason" required  lay-verify="required" placeholder="填写事故原因"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">我方情况</label>
        <div class="layui-input-block">
            <input type="text" name="oursitu" required  lay-verify="required" placeholder="情况"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">对方情况</label>
        <div class="layui-input-block">
            <input type="text" name="othersitu" required  lay-verify="required" placeholder="情况"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">处理结果</label>
        <div class="layui-input-block">
            <input type="text" name="result" required  lay-verify="required" placeholder="填写处理结果"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">我方承担金额</label>
        <div class="layui-input-block">
            <input type="text" name="ourmoney" required  lay-verify="required" placeholder="金额"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">对方承担金额</label>
        <div class="layui-input-block">
            <input type="text" name="othermoney" required  lay-verify="required" placeholder="金额"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保险承担金额</label>
        <div class="layui-input-block">
            <input type="text" name="insuremoney" required  lay-verify="required" placeholder="金额"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">事故备注</label>
        <div class="layui-input-block">
            <input type="text" name="information" required  lay-verify="required" placeholder=""  class="layui-input">
        </div>
    </div>


</form>


</body>
</html>